<template>
    <slot :controller="controller" :store="store" :model="model">
        <div :class="classNames" >
            <AppDrbar v-bind="$attrs" :counterData="store.counterData" :ctrlItems="store.ctrlItems" :caption="model.caption" :codeName="model.codeName" @itemClick="(item:any) => { handleSelectChange(item) }">
                <slot name="DrbarCaption" :controller="controller" :store="store" :model="model">
                    <AppIconText :text="$t(`${model.capPSLanguageRes}`, model.caption)" ></AppIconText>
                </slot>
            </AppDrbar>
        </div>
    </slot>
</template>
<script setup lang="ts">
// 基于template/src/widgets/{{appEntities}}/{{ctrls@DRBAR}}-drbar/{{spinalCase ctrl.codeName}}-drbar-base.vue.hbs生成
import { AppDrbar } from "@components/widgets/drbar";
import { useProps, useBasic, useAction, useController } from './default-drbar-hook';
import { DrbarActionType, IDrbarAbility, IDrbarStore, IParam } from "@/core/interface";

// 输入参数
const props = defineProps(useProps());

// 基础数据
const { 
    model,
    controlID, 
    getClassNames, 
    useNavParamsBind, 
    useEventBind, 
} = useBasic(props);

const emit = defineEmits<{
    (event: 'ctrl-action', name: string, action: DrbarActionType, data: IParam[]): void;
    (event: 'ctrl-init', name: string, data: IDrbarAbility): void;
    (event: 'ctrl-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
  return getClassNames(props);
});

const controller = useController(props, evt, { controlID });

const { handleSelectChange } = useAction(controller);

useNavParamsBind(controller, props);

const store: IDrbarStore = controller.getStore();

onMounted(() => {
    controller.ctrlMounted();
});

onUnmounted(() => {
    controller.ctrlDestroy();
})
</script>
